package com.dandan.mobilelover.dao.impl;

import java.util.List;

import javax.persistence.TypedQuery;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.dandan.mobilelover.dao.ci.ImageDao;
import com.dandan.mobilelover.entity.Image;

@Repository
public class ImageRepositoryImpl extends BaseJpaImpl implements ImageDao{

	@Override
	public List<Image> findAllByPageAndSort(Pageable page) {
		TypedQuery<Image> query = entityManager.createQuery("from Image order by updatedAt desc ", Image.class);
		 if (page.getOffset() >= 0 && page.getPageSize() > 0) {
			 query.setFirstResult(page.getOffset()).setMaxResults(page.getPageSize());
		}
		 return query.getResultList();
	}

}
